package ar.com.cooker.model;

import java.io.Serializable;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;
/**
 * Objeto Compuesto BO de recetas e integrantes.  
 * @author c02536
 *
 */
@Entity
@Table(name = "ck_Ingredient_Recipe")
@AssociationOverrides( {
	@AssociationOverride(name = "id.ingredient", joinColumns = @JoinColumn(nullable = false, name = "id_ingredient_fk")),
	@AssociationOverride(name = "id.recipe", joinColumns = @JoinColumn(nullable = false, name = "id_recipe_fk")) })
public class RecipeIngredient implements Serializable{

	private static final long serialVersionUID = 4147614097934738744L;
	
	@EmbeddedId
	private RecipeIngredientId id;
	
	@Column(length = 50)
	private String quantily;

	public RecipeIngredient() {
	}
	
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		RecipeIngredient that = (RecipeIngredient) o;

		if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null)
			return false;

		return true;
	}

	public int hashCode() {
		return (getId() != null ? getId().hashCode() : 0);
	}

	public void setId(RecipeIngredientId id) {
		this.id = id;
	}

	public RecipeIngredientId getId() {
		return id;
	}
	
	@Transient
	public Ingredient getIngredient() {
		return getId().getIngredient();
	}

	public void setIngredient(Ingredient ingredient) {
		this.id.setIngredient(ingredient);
	}

	public void setRecipe(Recipe recipe) {
		this.getId().setRecipe(recipe);
	}
	
	@Transient
	public Recipe getRecipe() {
		return this.getId().getRecipe();
	}

	public void setQuantily(String quantily) {
		this.quantily = quantily;
	}

	public String getQuantily() {
		return quantily;
	}
	
}
